package com.zpark;

public class Demo04 {
    public static void main(String[] args) throws InterruptedException {
        long time1 = System.currentTimeMillis();//获得你的代码执行前的毫秒数
        //代码
        int count = 0;
        System.out.print("100以内的素数为:");
        for (int i = 2; i <= 100; i++) {//遍历2-100的自然数，因为任何数除以1都等于它本身的数，所以i从2开始
            boolean flag = true;
            for (int j = 2; j <= Math.sqrt(i); j++) {
                Thread.sleep(10);
                if (i % j == 0) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                count++;
                System.out.print(i + " ");
            }

        }
        long time2 = System.currentTimeMillis();//获得你的代码执行后的毫秒数
        System.out.println();
        System.out.println("本段代码执行效率是："+ (time2 - time1));
    }
}
